import sys
from PyQt6.QtWidgets import QApplication,QDialog
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QPalette
from Ui_dialog import Ui_Dialog

class MyQDialog(QDialog):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        # 设置默认选中 radioButtonBlack
        self.ui.radioButtonBlack.setChecked(True)
        
        self.ui.radioButtonRed.clicked.connect(self.set_text_color)
        self.ui.radioButtonBlack.clicked.connect(self.set_text_color)
        self.ui.radioButtonYellow.clicked.connect(self.set_text_color)
    def on_btnOk_clicked(self):
        print('Ok')
    def on_btnClean_clicked(self):
        self.ui.textEdit.clear()
    def on_btnClose_clicked(self):
        print('Close')
    def on_checkBoxBold_toggled(self,checked):
        font = self.ui.textEdit.font()
        font.setBold(checked)
        self.ui.textEdit.setFont(font)  
    def on_checkBoxItalic_toggled(self,checked):
        font = self.ui.textEdit.font()
        font.setItalic(checked)
        self.ui.textEdit.setFont(font)
    def on_checkBoxUnderline_toggled(self,checked):
        font = self.ui.textEdit.font()
        font.setUnderline(checked)
        self.ui.textEdit.setFont(font)
    def set_text_color(self):
        pallete= self.ui.textEdit.palette()
        if self.ui.radioButtonRed.isChecked():
            pallete.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.red)
        elif self.ui.radioButtonBlack.isChecked():
            pallete.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.black)
        elif self.ui.radioButtonYellow.isChecked():
            pallete.setColor(QPalette.ColorRole.Text, Qt.GlobalColor.yellow)
        self.ui.textEdit.setPalette(pallete)

    

        
        

if __name__ == '__main__':
    app = QApplication(sys.argv)
    dialog = MyQDialog()
    dialog.show()
    sys.exit(app.exec())